home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / pcr / pcr4_4.lha / DIST / loading / time_setjmp.c < prev    next >
C/C++ Source or Header  |  1989-04-03  |  3KB  |  115 lines

  1. /* begincopyright
  2.   Copyright (c) 1988 Xerox Corporation. All rights reserved.
  3.   Use and copying of this software and preparation of derivative works based
  4.   upon this software are permitted. Any distribution of this software or
  5.   derivative works must comply with all applicable United States export
  6.   control laws. This software is made available AS IS, and Xerox Corporation
  7.   makes no warranty about the software, its performance or its conformity to
  8.   any specification. Any person obtaining a copy of this software is requested
  9.   to send their name and post office or electronic mail address to:
  10.     PCR Coordinator
  11.     Xerox PARC
  12.     3333 Coyote Hill Rd.
  13.     Palo Alto, CA
  14.   endcopyright */
  15. /* Copyright 1987, Xerox, Inc., 
  16.  *    written by Mark Weiser
  17.  *
  18.  * $Log:    time_setjmp.c,v $
  19.  * Revision 1.3  88/09/10  21:56:20  xr
  20.  * *** empty log message ***
  21.  * 
  22.  * Revision 1.2  88/09/10  21:41:48  xr
  23.  * *** empty log message ***
  24.  * 
  25.  * Revision 1.1  88/09/10  21:37:24  xr
  26.  * Initial revision
  27.  * 
  28.  */
  29. #ifndef lint
  30. static char rcsid[] = "$Header: time_setjmp.c,v 1.3 88/09/10 21:56:20 xr Exp $";
  31. #endif
  32.  
  33. #include <setjmp.h>
  34. #include <xr/unwind.h>
  35.  
  36. jmp_buf jb;
  37.  
  38. xr_jmp_buf cjb;
  39.  
  40. #define CEDAR
  41. #ifdef CEDAR
  42. #define LONGJMP    xr_longjmp
  43. #define SETJMP    my_setjmp
  44. #else
  45. #define LONGJMP    _longjmp
  46. #define SETJMP    _setjmp
  47. #endif
  48.  
  49. typedef int RegType;
  50.  
  51. main(argc, argv)
  52. int argc;
  53. char **argv;
  54. {
  55.     int x, iterations;
  56.     register RegType a, b, c, d, e, f, g, h, i, j, k, l, m, n;
  57.     a = (RegType)1; b = (RegType)2; c = (RegType)3; d = (RegType)4; e = (RegType)5; f = (RegType)6; g = (RegType)7; h = (RegType)8; i = (RegType)9;
  58.     j = (RegType)10; k = (RegType)11; l = (RegType)12; m = (RegType)13; n = (RegType)14;
  59.     if (argc < 2) {
  60.         printf("Usage: %s #iterations.\n", argv[0]);
  61.         exit(1);
  62.     }
  63.     iterations = atol(argv[1]);
  64.     x = 0;
  65.     if (! init_dyload(argv[0])) {
  66.         printf("Something wrong in init_dyload.\n");
  67.         abort();
  68.     }
  69.     if (SETJMP(&cjb)) {
  70.         if (x++ < iterations) godeep();
  71.         printf("Got a non-zero return from xr set_jmp after %d iterations, vals: ", iterations);
  72.         dump_vars(a, b, c, d, e, f, g, h, i, j, k, l, m, n);
  73.         exit(0);
  74.     } else {
  75.         printf("Got a zero return from xr set_jmp, vals: ");
  76.         dump_vars(a, b, c, d, e, f, g, h, i, j, k, l, m, n);
  77.     }
  78.      a = (RegType)43; b = (RegType)43; c = (RegType)43; d = (RegType)43; e = (RegType)43; f = (RegType)43; g = (RegType)43; h = (RegType)43; i = (RegType)43;
  79.     j = (RegType)43; k = (RegType)43; l = (RegType)43; m = (RegType)43; n = (RegType)43;
  80.     use_vars(a, b, c, d, e, f, g, h, i, j, k, l, m, n);
  81.     godeep();
  82.     exit();
  83. }
  84.  
  85. godeep()
  86. {
  87. godeeper();
  88. }
  89.  
  90. godeeper()
  91. {
  92. smash_regs();
  93. }
  94.  
  95. smash_regs()
  96. {
  97.     LONGJMP(&cjb);
  98. }
  99.  
  100. dump_vars(a, b, c, d, e, f, g, h, i, j, k, l, m, n)
  101. {
  102.     printf("%d %d %d %d %d %d %d %d %d %d %d %d %d %d\n",a, b, c, d, e, f, g, h, i, j, k, l, m, n);
  103. }
  104.  
  105. use_vars(a, b, c, d, e, f, g, h, i, j, k, l, m, n)
  106. {
  107. }
  108.  
  109. /* use this to get the 'level' parameter into xr_setjmp */
  110. my_setjmp(a)
  111. long a;
  112. {
  113.   xr_setjmp(a, 0);
  114. }
  115.